package com.templeix.jfinal.base;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.templeix.timeaxis.model.SysMenu;

public class BaseService {
	public static Map<Integer, List<SysMenu>> getMenuMap(int roleId) {
		String menuIds = " select menu_id from t_sys_role_menu where role_id = " + roleId;

		Map<Integer, List<SysMenu>> map = new HashMap<Integer, List<SysMenu>>();

		String sqlWhere = " where state = 1 and parent_id = ? " 
					+ "and id in (" + menuIds + ") order by sort ";
		System.out.println("sqlWhere:" + sqlWhere);
		// 获取一级菜单
		List<SysMenu> rootMenuList = SysMenu.dao.findByWhere(sqlWhere, 0);
		if (rootMenuList == null || rootMenuList.size() == 0) {
			return null;
		}
		map.put(0, rootMenuList);
		
		// 获取子目录
		for (SysMenu sysMenu : rootMenuList) {
			System.out.println("name:" + sysMenu.getStr("name"));
			List<SysMenu> subMenulist = SysMenu.dao.findByWhere(sqlWhere, sysMenu.getInt("id"));			
			map.put(sysMenu.getInt("id"), subMenulist);
		}

		return map;
	}	
}
